package de.sonntagsfarben.puremvc.as3.modules
{
	import de.sonntagsfarben.Toplevel;
	import de.sonntagsfarben.puremvc.as3.modules.IModule;

	import org.puremvc.as3.multicore.interfaces.IFacade;
	import org.puremvc.as3.multicore.utilities.pipes.interfaces.IPipeFitting;
	import org.puremvc.as3.multicore.utilities.pipes.plumbing.JunctionMediator;

	/*
	   andere möglichkeit wäre die facade zum IPipeAware zu machen ???
	 */
	public class PipeAwareModule extends Toplevel implements IModule
	{
		public static const NAME : String = "PipeAwareModule";

		protected var facade : IFacade;
		protected var moduleID : String;

		private static var SERIAL : int = -1;


		public function PipeAwareModule( facade : IFacade )
		{
			super();
			this.facade = facade;
		}

		protected function getUniqueID() : String
		{
			moduleID = NAME + '/' + ( ++SERIAL );
			return moduleID;
		}


		public function getID() : String
		{
			return moduleID;
		}


		/**
		 * Accept an input pipe.
		 * <P>
		 * Registers an input pipe with this module's Junction.
		 */
		public function acceptInputPipe( name : String , pipe : IPipeFitting ) : void
		{
			facade.sendNotification( JunctionMediator.ACCEPT_INPUT_PIPE , pipe , name );
		}

		/**
		 * Accept an output pipe.
		 * <P>
		 * Registers an input pipe with this module's Junction.
		 */
		public function acceptOutputPipe( name : String , pipe : IPipeFitting ) : void
		{
			facade.sendNotification( JunctionMediator.ACCEPT_OUTPUT_PIPE , pipe , name );
		}
	}
}